/*
 * Copyright (C) 2009 Yury Kudryashov.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package name.kudryashov.base;

import java.util.Collection;
import java.util.Map;

/**
 * Utility methods for checking various conditions
 */
public final class Is {

    // Prohibit instances of this class
    private Is() {}

    /**
     * Checks if the given string is either null or empty.
     * @param s string
     * @return true if the given string is null or empty, false otherwise
     */
    public static boolean nullOrEmpty(String s) {
        return s == null || s.isEmpty();
    }

    /**
     * Checks if the given collection is either null or empty.
     * @param collection collection
     * @return true if the given collection is null or empty, false otherwise
     */
    public static boolean nullOrEmpty(Collection<?> collection) {
        return collection == null || collection.isEmpty();
    }

    /**
     * Checks if the given map is either null or empty.
     * @param map map
     * @return true if the given map is null or empty, false otherwise
     */
    public static boolean nullOrEmpty(Map<?, ?> map) {
        return map == null || map.isEmpty();
    }

    /**
     * Checks if the given array is either null or empty.
     * @param ts array
     * @return true if the given array is null or empty, false otherwise
     */

    public static <T> boolean nullOrEmpty(T[] ts) {
        return ts == null || ts.length == 0;
    }
}
